using UnityEngine;

public class TeamComputer : Team
{
	public override void OnJumpBall()
	{
		base.OnJumpBall();
		for (int i = 0; i < Team.PlayerCount; i++)
		{
			getPlayer(i).OnJumpBall();
		}
		playerC.LookAt(MathHelper.setY(Instance<CameraController>.instance.getCameraPos(), 0f));
		Invoke("invokeJumpBall", 0.45f);
		playerC.AI.time_Stop = time_think_at_offense;
	}

	private void invokeJumpBall()
	{
		playerC.AI.do_jumpball();
	}

	public override void OnBaseLine(Vector3 targetPos)
	{
		base.OnBaseLine(targetPos);
		Player player = null;
		for (int i = 0; i < 5; i++)
		{
			if (getPlayer(i).AI.isInState(PlayerAIState_Tumble.getInstance()))
			{
				player = getPlayer(i);
				break;
			}
		}
		Player player2 = getPlayer(PlayerType.CENTER);
		Player player3 = getPlayer(PlayerType.POINTGUARD);
		if (player != null)
		{
			if (player2 == player)
			{
				player2 = getPlayer(PlayerType.POWERFORWARD);
			}
			else if (player3 == player)
			{
				player3 = getPlayer(PlayerType.SHOOTINGGUARD);
			}
		}
		player2.AI.do_baseline(targetPos);
		player3.acceptbasslineball_targetPos = getAccetpBaseLineBallPos(targetPos);
		player3.AI.do_acceptbaselineball();
		for (int j = 0; j < Team.PlayerCount; j++)
		{
			if (getPlayer(j) != player2 && getPlayer(j) != player3 && !getPlayer(j).AI.isInState(PlayerAIState_Tumble.getInstance()))
			{
				getPlayer(j).AI.do_offense_findpos();
			}
		}
		doSingleCrossover(player3);
	}

	public override void OnParaBaseLine()
	{
		base.OnParaBaseLine();
		for (int i = 0; i < Team.PlayerCount; i++)
		{
			getPlayer(i).AI.time_Stop = 0f;
			getPlayer(i).AI.do_defense_defense();
		}
	}

	public override void OnBallIn()
	{
		base.OnBallIn();
		for (int i = 0; i < Team.PlayerCount; i++)
		{
			if (Instance<Ball>.instance.isDunk)
			{
				if (!getPlayer(i).isInState(PlayerStateBehavior_Shoot.getInstance()))
				{
					getPlayer(i).AI.do_defense_defense();
				}
			}
			else
			{
				getPlayer(i).AI.do_defense_defense();
			}
		}
	}

	public override void OnParaBallIn()
	{
		base.OnParaBallIn();
		for (int i = 0; i < Team.PlayerCount; i++)
		{
			getPlayer(i).AI.do_idle();
		}
	}

	public override void OnShoot(Player player)
	{
		base.OnShoot(player);
		if (Instance<Court>.instance.isInState(CourtStateFreeThrow.getInstance()))
		{
			Vector3 target = (offenseDirection != 0) ? Global.posBallIn_Right_Ground : Global.posBallIn_Left_Ground;
			Player player_ClosestToTarget = getPlayer_ClosestToTarget(target);
			player_ClosestToTarget.AI.do_offense_grabrebound();
		}
		Vector3 target2 = (offenseDirection != OffenseDirection.RIGHT) ? Global.posBallIn_Right_Ground : Global.posBallIn_Left_Ground;
		Player player_ClosestToTarget2 = getPlayer_ClosestToTarget(target2);
		if (!player_ClosestToTarget2.isInState(PlayerStateBehavior_Shoot.getInstance()))
		{
			player_ClosestToTarget2.AI.do_defense_defense();
		}
	}

	public override void OnParaShoot()
	{
		base.OnParaShoot();
		bool flag = false;
		PlayerType playerType = PlayerType.CENTER;
		for (int i = 0; i < Team.PlayerCount; i++)
		{
			if (getPlayer(i).IsCanBlock())
			{
				getPlayer(i).AI.do_defense_block();
				flag = true;
				playerType = getPlayer(i).playerType;
				break;
			}
		}
		Vector3 target = (offenseDirection != 0) ? Global.posBallIn_Left_Ground : Global.posBallIn_Right_Ground;
		if (!flag)
		{
			Player player_ClosestToTarget = getPlayer_ClosestToTarget(target);
			player_ClosestToTarget.AI.do_defense_grabrebound();
			getPlayer_ClosestTeammate(player_ClosestToTarget).AI.do_defense_grabrebound();
			return;
		}
		Player player_ClosestToTarget2 = getPlayer_ClosestToTarget(target);
		if (player_ClosestToTarget2.playerType != playerType)
		{
			player_ClosestToTarget2.AI.do_defense_grabrebound();
		}
		getPlayer_ClosestTeammate(player_ClosestToTarget2).AI.do_defense_grabrebound();
	}

	public override void OnGetBall(Player player)
	{
		base.OnGetBall(player);
		player.AI.do_offense_dribble();
		doSingleCrossover(player);
	}

	public override void OnParaGetBall()
	{
		base.OnParaGetBall();
		for (int i = 0; i < Team.PlayerCount; i++)
		{
			getPlayer(i).AI.time_Stop = 0f;
			getPlayer(i).AI.do_defense_defense();
		}
	}

	public override void setIsOffense(bool _isOffense)
	{
		base.setIsOffense(_isOffense);
		if (!_isOffense)
		{
			for (int i = 0; i < Team.PlayerCount; i++)
			{
				getPlayer(i).isSingleCrossOver = false;
			}
			return;
		}
		for (int j = 0; j < Team.PlayerCount; j++)
		{
			getPlayer(j).AI.setCrossoverCount();
			getPlayer(j).AI.time_Stop = 0f;
		}
	}

	private void doSingleCrossover(Player player)
	{
		if (MathHelper.isInPercent(percent_single_crossover))
		{
			player.isSingleCrossOver = true;
			for (int i = 0; i < Team.PlayerCount; i++)
			{
				if (getPlayer(i) != player)
				{
					getPlayer(i).isSingleCrossOver = false;
				}
			}
		}
		else
		{
			for (int j = 0; j < Team.PlayerCount; j++)
			{
				getPlayer(j).isSingleCrossOver = false;
			}
		}
	}
}
